define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_detail(result){
			if(false){
				result = '{"success": true,"msg": "","result":{"title": "求购扳手","id": "001","end_time": "2017/01/01 23:59:59","address": "上大路沪太路","invoice_type": "1","phone": "18912345678","memo": "急需该类商品，量大的来","goods": [{"name": "扳手","describe": "量大，价好","cat_type": "手动工具/扳手/活络扳手","brand_need": true,"brand_name": "东成","count": 2,"photo": [{"id": "001","image": "img/upload/pro-img01.jpg"},{"id": "002","image": "img/upload/pro-img01.jpg"}]},{"name": "扳手2","describe": "数量大且质量好","cat_type": "手动工具/扳手/活络扳手","brand_need": true,"brand_name": "东成","count": 2,"photo": [{"id": "001","image": "img/upload/pro-img01.jpg"},{"id": "002","image": "img/upload/pro-img01.jpg"}]}],"offer_list": [{"offer_time": "2017/01/01 08:30:00","store_name": "东成1","region": "江苏东城","price": 5},{"offer_time": "2017/01/01 08:30:00","store_name": "东成2","region": "江苏东城","price": 5}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_offerdetail(result){
			if(false){
				result = '{"success": true,"msg": "","result": {"info_id": "001","store_name": "世达","region_id": "001","region": "江苏"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		function get_data_offer(result){
			if(false) {
				result = '{"success": true,"msg": "","result": {"id": "001"},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		
		//返回信息
		return {
			//获取全球详细
			goods_detail: function(id, callback) {
				Http.post({
							method : 'info.findgoods.detail',
							id : id
						},
						function(result) {
							//请求成功
							if(callback)
								callback(get_data_detail(result).result,result.process_time);
						},
						function(e) {
							//请求异常

						},
						function() {
							//请求完成，一般不做什么事情
						}
				);
			},
			//获取供应商信息
			offerdetail: function(info_id, callback) {
				Http.post({
							method : 'info.findgoods.offerdetail',
							info_id : info_id
						},
						function(result) {
							//请求成功
							if(callback)
								callback(get_data_offerdetail(result).result);
						},
						function(e) {
							//请求异常

						},
						function() {
							//请求完成，一般不做什么事情
							
						}
				);
			},
			//产品报价
			offer:function(info_id, store_id, price, callback) {
				Http.post({
							method : 'info.findgoods.offer',
							info_id : info_id,
							store_id : store_id,
							price : price
						},
						function(result) {
							//请求成功
							if(callback)
								callback(get_data_offer(result));
						},
						function(e) {
							//请求异常

						},
						function() {
							//请求完成，一般不做什么事情
							
						}
				);
		},
		store_info:function(callback){
			Http.post({
				method:'member.memberdata.get_store',
			},function(result){
				if(callback)
				callback(result.result);
			})
		}

		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Myproductdetail", factory);
});